import { createI18n } from 'vue-i18n'
import { Locale } from 'vant'

// 本地语言包
import zhCN from './zh_CN'
import enUS from './en_US'

// Vant语言包
import zhHK from 'vant/lib/locale/lang/zh-HK'
import enUSVant from 'vant/lib/locale/lang/en-US'

const messages = {
  zh: {
    ...zhCN,
    ...zhHK
  },
  en: {
    ...enUS,
    ...enUSVant
  }
}

// 初始化i18n
export const i18n = createI18n({
  legacy: false,
  globalInjection: true,
  locale: navigator.language.split('-')[0] || 'en',
  fallbackLocale: 'zh',
  messages
})

// Vant语言切换函数
export function setVantLocale(lang) {
  Locale.use(lang, messages[lang]?.vant || enUSVant)
}